<!--
 * @Author: wjk
 * @Date: 2019-12-31 15:40:51
 * @LastEditors: wjk
 * @description: 商品详情页
 -->
<template>
  <base-page-view v-if="goods.goods_id || goods.title" :class-name="'commodity-container ' + (commodityType === 'bonusGift' ? 'bonus-gift' : '')" :show-to-top="!showPopup">
    <base-nav :refresh-flag="refreshFlag" nav-position="fixed" :background="`rgba(255,255,255, ${pageScrollTop > 50 ? 1 : pageScrollTop / 55})`">
      <view slot="left" class="commodity-header">
        <view v-if="!isShare" class="header-control">
          <view class="control-box left-control" @click="_pageBack">
            <image class="nav-icon" src="/static/images/icon/icon_return_circle.png" mode="aspectFit" />
          </view>
          <view class="control-box right-control">
            <image class="nav-icon click-active" style="padding: 0 20rpx;" src="/static/images/icon/icon_more_menu.png" mode="aspectFit" @click="headerMenu = !headerMenu" />
            <view v-if="headerMenu" class="right-part">
              <view class="menu-item click-active" @click="toHome">
                <image class="nav-icon " src="/static/images/icon/icon_top_home.png" mode="aspectFit" />
                <view class="nav-text">去首页</view>
              </view>
              <!-- <view v-if="showCartButton" class="menu-item cartIconBox  click-active" @click="linktoCart">
                <view v-if="cartNums" class="cartNums">{{ cartNums > 9 ? '9+' : cartNums }}</view>
                <image class="nav-icon" src="/static/images/icon/icon_top_cart.png" mode="aspectFit" />
                <view class="nav-text">购物车</view>
              </view> -->
            </view>
          </view>
        </view>
        <view v-else class="share-back" @click="goHome">
          <image class="home-nav-icon" src="/static/images/icon/icon_nav_home.png" mode="aspectFit" />
        </view>
      </view>
      <view v-show="pageScrollTop > 50" slot="title">
        <view class="head_title">
          <span :class="{ title_active: currentPos === 0 }" @click="scrollToTab(0)">商品</span>
          <span v-show="showKoubei" :class="{ title_active: currentPos === 1 }" @click="scrollToTab(1)">口碑</span>
          <span v-show="showComment" :class="{ title_active: currentPos === 2 }" @click="scrollToTab(2)">评价</span>
          <span :class="{ title_active: currentPos === 3 }" @click="scrollToTab(3)">详情</span>
        </view>
      </view>
    </base-nav>
    <!-- <view class="goods-container"> -->
    <view class="swiper-components">
      <b-swiper class-name="commodity-swiper" is-home border-radius="0rpx" :merge-dots="{ bottom: 20 }" :swiper-list="bannerList"></b-swiper>
      <!-- <image v-if="goods.tag_img" class="item-tag" :src="goods.tag_img" /> -->
    </view>
    <!-- 分享按钮 -->
    <url-image src="/static/images/member/detail/share.png" width="60" height="60" className="share-btn-icon" @click="navButtonHandle('shareDialog')"></url-image>
    <commodity-title
      :all-data="allData"
      :goods="goods"
      :goods-tab="allData.goods_tag"
      :is-box-goods="isBoxGoods"
      :is-group-goods="isGroupGoods"
      :group-buy="GroupBuyInfo"
      :commodity-type="commodityType"
      :wait-sale="waitSale"
      :query="query"
      :is-bookmark="is_bookmark"
      @collectCommodity="collectCommodity"
    />
    <commodity-option
      ref="option"
      :hide-menu="hideMenu"
      :commodity-type="commodityType"
      :all-data="allData"
      :query="query"
      :show-coupon="showCoupon"
      @dialogConfirm="dialogConfirm"
      @validProps="validProps"
      @modulesData="handleActivityChange"
      @groupHandle="groupHandle"
    />
    <!-- 商品评论 -->
    <view v-if="!hideMenu" id="userKB">
      <commodity-koubei :query="query" :show-comment.sync="showKoubei" :goods="goods" />
    </view>
    <view v-if="!hideMenu" id="userCm">
      <commodity-comment :query="query" pic-limit :show-comment.sync="showComment" :goods="goods" />
    </view>
    <commodity-intro id="goodsDetail" :intro="goods.detail" />
    <!-- 详情底部按钮控制 -->
    <commodity-nav
      ref="nav"
      :hide-menu="hideMenu"
      :unab-text="unabText"
      :show-share-button="showShareButton"
      :show-cart-button="showCartButton"
      :all-data="allData"
      :goods="goods"
      :group-buy="GroupBuyInfo"
      :is-send="isSend"
      :wait-sale="waitSale"
      :buy-enable="buyEnable"
      :commodity-type="commodityType"
      @navButtonHandle="navButtonHandle"
      :cartNums="cartNums"
    />
    <commodity-share ref="shareRef" :share-option="shareOption" />
    <confirm-popup ref="confirmShow" :show-close="true" />
    <view v-if="shareUserInfo.uid" class="share-container" :class="{ hide: hideShareInfo }" @click="handleToggle">
      <view class="share-right">
        <image class="share-avatar" :src="shareUserInfo.head_img" />
      </view>
      <view class="share-left">
        <view class="share-username">{{ shareUserInfo.nickname }}</view>
        <view class="share-tip">为您推荐了一款必买好物!</view>
      </view>
    </view>
    <share-btn v-if="!token" />
  </base-page-view>
</template>

<script>
import { mapState } from 'vuex'
import { getUserLevel } from '@/utils/common'
import ShareBtn from '@/components/customModules/modules/shareBtn.vue'
import baseNav from '@/components/base/base-nav.vue'
import CommodityNav from './components/commodity-nav'
import CommodityTitle from './components/commodity-title'
import CommodityOption from './components/commodity-option'
import CommodityIntro from './components/commodity-intro'
import CommodityShare from './components/commodity-share'
import confirmPopup from '@/components/confirmPopup/index'
import CommodityComment from './components/commodity-comment' // 商品评论
import CommodityKoubei from './components/commodity-koubei' // 商品口碑
import BSwiper from '@/components/base/base-swiper'
import { getVipUrl } from '@/apis/Promotion'
import { h5NavigateTo } from '@/utils/navigateTo'
import { parseTime, inputCheckNumber, formatUrlParam, throttle, getQueryString } from '@/utils/tools'
// #ifdef H5
// import AppUtils from '@/utils/AppUtils'
// #endif
import './index.scss'
export default {
  components: {
    ShareBtn,
    CommodityComment,
    CommodityKoubei,
    BSwiper,
    baseNav,
    CommodityTitle,
    CommodityOption,
    CommodityNav,
    CommodityIntro,
    CommodityShare,
    confirmPopup
  },
  data() {
    return {
      shareOption: {}, // 分享自定义设置
      scrollTime: null,
      showComment: false,
      showKoubei: false,
      currentPos: 0,
      goodsDetailPos: 0, // 商品详情页面所处位置
      userKBPos: 0, // 用户口碑页面所处位置
      userCmPos: 0, // 用户评论页面所处位置
      query: {},
      groupInfo: {},
      headerMenu: false, // 顶部菜单
      refreshFlag: false,
      commodityType: 'single', // 商品类型 single: 单品, package: 套餐, partner: 城市合伙人, boxGoods:箱起, promote: M+N. groupBuy: 拼团; bonusGift: 官方礼包
      hideMenu: false, // 只可浏览详情
      isSend: true, // 是否可配送
      pageScrollTop: 0, // 页面滑动距离
      cartNums: null, // 购物车数量
      is_bookmark: false, // 是否收藏
      isBoxGoods: false, // 是否是箱起
      isGroupGoods: false, // 是否拼团商品
      takeInshareGroup: false,
      goodsOriginFromType: 0, // 拼团用商品原始from_type
      partner: {}, // 城市合伙人object
      partnerRole: '', // 城市合伙人权限
      allData: {},
      groupParam: {},
      defaultAddress: {},
      goods: {
        commission: 0,
        banner_list: [],
        goods_pack: {}
      },
      GroupBuyInfo: {},
      firstseat: uni.getStorageSync('firstseat') || '', // 埋点 - 前置模块
      preseat: uni.getStorageSync('preseat') || '', // 埋点 - 前向页面
      isShare: false,
      hideShareInfo: false,
      shareUserInfo: {},
    }
  },
  computed: {
    ...mapState(['showPopup', 'token', 'userInfo']),
    buyEnable() {
      // 是否可以购买
      if (this.waitSale) {
        return false
      }
      // 是否可以配送
      if (!this.isSend) {
        return false
      }
      if (this.goods.type === 4 && this.goods.status !== 5) {
        return true
      }
      // 箱起云仓
      if (this.allData.series_type === 3) {
        if (!this.userInfo.boxPermission || !this.userInfo.boxPermission.length) {
          return false
        }
      }
      if (this.goods.from_type * 1 === 9) {
        if (!this.partner.is_show || !this.partnerRole) {
          return false
        }
        const tempRole = this.partnerRole.split(',')
        if (!this.userInfo || tempRole.indexOf(this.userInfo.current_member_card_type + '') < 0) {
          return false
        }
      }
      if (this.goods.status === 3 || this.goods.status === 0) {
        if (this.goods.from_type === 8) {
          if (this.user && this.userInfo) {
            if (this.userInfo.current_member_card_type > 1) {
              return false
            }
          }
        }
        if (!this.checkSkuNum(this.goods) && (this.goods.type === 1 || this.goods.type === 0) && !this.bonus_gift_id) {
          // 如果是3800礼包
          if (this.commodityType === 'bonusGift' && this.allData.gifts.length > 0) {
            return true
          }
          return false
        }
        return true
      }
      return false
    },
    waitSale() {
      // 预售时间
      let saletime = ''
      if (this.query.date && this.query.date > this.goods.sales_time) {
        saletime = this.query.date
      } else {
        saletime = this.goods.sales_time
      }
      if (!saletime) {
        return ''
      }
      if (new Date(this.goods.sys_time * 1000) < new Date(saletime * 1000)) {
        return parseTime(new Date(saletime * 1000), '{m}月{d}日 {h}:{i}') + '开售'
      }
      return ''
    },
    unabText() {
      // 不可购买按钮文字
      let text = '该商品已售罄'
      switch (this.goods.status) {
        case 0:
          if (this.commodityType === 'bonusGift' && this.allData.gifts.length <= 0) {
            text = '不符合购买条件'
          }
          break
        case 1:
          text = '该商品还未开售'
          break
        case 2:
          text = '该商品正在预售'
          break
        case 3:
          if (this.goods.from_type === 9) {
            // text = '加入购物车'
            if (this.token && this.userInfo) {
              if (this.partnerRole.indexOf('3') > -1 && this.partnerRole.indexOf('2') < 0) {
                text = '仅董事可以购买'
              }
              if (this.partnerRole.indexOf('2') > -1 && this.partnerRole.indexOf('3') < 0) {
                text = '仅大区会员可以购买'
              }
              if (this.partnerRole.indexOf('2') > -1 && this.partnerRole.indexOf('3') > -1) {
                text = '仅大区会员和董事可以购买'
              }
            }
            return text
          }
          if (this.goods.from_type === 7 || this.goods.from_type === 8) {
            // text = '加入购物车'
            if (this.token && this.userInfo) {
              if (this.userInfo.current_member_card_type === 3) {
                text = '董事会员无法购买'
              }
              if (this.userInfo.current_member_card_type === 2) {
                text = '大区会员无法购买'
              }
              if (this.userInfo.current_member_card_type === 1 && this.goods.from_type === 7) {
                text = '碧选会员无法购买'
              }
            }
            return text
          }
          if (!this.buyEnable) {
            text = '该商品已售罄'
          }
          if (this.allData.series_type === 3) {
            text = '不符合购买条件'
          }
          // // 商品配送点击
          if (!this.isSend) {
            text = '不支持配送'
          }
          break
        case 4:
          text = '该商品已售罄'
          break
        case 5:
          text = '该商品已下架'
          break
        default:
          text = '该商品已下架'
          break
      }
      return text
    },
    // 轮播图列表
    bannerList() {
      let bannerArr = []
      // 组合套餐
      bannerArr = this.goods.banner_list.length ? this.goods.banner_list : [{ url: this.goods.pic }]
      return bannerArr
    },
    showCoupon() {
      let show = true
      const fromtype = this.goods.from_type * 1
      const type = this.goods.type * 1
      if (this.commodityType !== 'single' || !this.userInfo || !this.userInfo.uid) {
        return false
      }
      if (fromtype <= 300 && fromtype > 201) {
        return false
      }
      switch (fromtype) {
        case 19:
        case 22:
        case 25:
          show = false
          break
        default:
          break
      }
      if (this.GroupBuyInfo.availableGroupBuy === true || type === 4) {
        show = false
      }
      return show
    },
    showShareButton() {
      let show = true
      if (!this.goods) {
        show = false
      } else if (this.commodityType !== 'single' && this.commodityType !== 'package') {
        show = false
      } else {
        const fromtype = this.goods.from_type * 1
        if (fromtype <= 300 && fromtype > 101) {
          show = false
        }
        switch (fromtype) {
          case 1:
          case 3:
            if (this.commodityType === 'groupBuy') {
              if (this.groupInfo.secondLeft > 0 || !this.groupInfo.headVOList) {
                show = false
              } else {
                show = true
              }
            }
            break
          case 7:
          case 8:
          case 9:
          case 14:
          case 18:
          case 19:
          case 20:
            show = false
            break
          case 22:
            show = true
            break
          case 101:
            show = true
            break
          default:
            break
        }
        if (this.GroupBuyInfo.availableGroupBuy === true) {
          show = false
        }
      }
      return show
    },
    showCartButton() {
      if (!this.goods || this.waitSale) {
        return false
      }
      if (this.commodityType !== 'single' && this.commodityType !== 'package') {
        return false
      }
      let show = true
      const fromtype = this.goods.from_type * 1
      const type = this.goods.type * 1
      if (fromtype <= 300 && fromtype > 100) {
        return false
      }
      switch (fromtype) {
        case 7:
        case 8:
        case 9:
        case 13:
        case 14:
        case 18:
        case 19:
        case 20:
        case 22:
        case 25:
        case 31:
          show = false
          break
        default:
          break
      }
      switch (type) {
        case 4:
          show = false
          break
        default:
          ''
      }
      return show
    },
    topShowText() {
      // if (!this.user) {
      if (this.goods.from_type === 9) {
        return '箱起价'
      }
      if (this.goods.from_type === 14) {
        return '门店价'
      }
      return '碧选价'
    },
  },
  provide() {
    return {
      initShare: this.initShare
    }
  },
  watch: {
    // 当有评论时 重新获取商品评论距离顶部高度
    showComment(val) {
      if (val) {
        this.$nextTick(() => {
          this.getElScrollTop()
        })
      }
    },
    showKoubei(val) {
      if (val) {
        this.$nextTick(() => {
          this.getElScrollTop()
        })
      }
    }
  },
  onShareAppMessage(res) {
    return this.$queryShareOption(res, this.shareOption)
  },
  onPullDownRefresh() {
    // this.refreshFlag = true  还是去掉吧
    this._initCommodity()
  },
  async onLoad(option) {
    // @property (nonatomic, copy) NSString *goods_id;//商品ID
    // @property (nonatomic, strong) NSNumber *goods_type;//类型。1 普通商品 2套餐
    // @property (nonatomic, strong) NSNumber *from_type;//@1单品 @2秒杀 @3套餐 @4预售 @5专题 @6活动 @7vip  @8钻石 @9城市合伙人套餐 @10赠品
    // @property (nonatomic, strong) NSNumber *pack_type;//套餐类型  @1固定套餐   @2自由组合套餐  @3城市合伙人套餐
    // @property (nonatomic, copy) NSString *activity_id;//活动id
    // @property (nonatomic, copy) NSString *freight_template_id;//运费模板id
    // @property (assign, nonatomic) CGFloat director_share_commission;//董事会员等级拥金 2019.09.17 许杜生添加
    // @property (assign, nonatomic) CGFloat region_share_commission;////钻石会员等级拥金 2019.09.17 许杜生添加
    // @property (nonatomic, assign) NSInteger seckill_start_time;//秒杀开始时间
    // @property (nonatomic, assign) NSInteger seckill_end_time;//秒杀结束时间
    // @property (nonatomic, assign) NSInteger sys_time;//服务器当前时间
    // @property (nonatomic,strong) NSString *preseat;//详情页来源（前置页面） 2019.04.27 许杜生添加
    // @property (nonatomic,strong) NSString *firstseat;//前向模块                        2019.07.05 许杜生添加
    // @property (nonatomic, copy, nullable) NSString *groups_buying_id;//拼团id
    
    this.shareOption = {}
    this.isShare = !!option.isShare
    this.isBoxGoods = false
    this.query = option
    // 判断商品类型
    if (this.query.type) {
      this.$set(this, 'commodityType', this.query.type)
    }
    if (this.query.from_type * 1 === 9) {
      this.$set(this, 'commodityType', 'partner')
      this.isBoxGoods = true
    }
    if (this.query.bonus_gift_id) {
      this.$set(this, 'commodityType', 'bonusGift')
      this.isBoxGoods = true
    }
    if (this.query.type === 'boxGoods') {
      this.isBoxGoods = true
    }
    this.hideMenu = Boolean(this.query.hideMenu)
    uni.$on('login', this._reInit)
    await this._initCommodity()
    this.getShareUser(option)
  },
  onPageScroll(object) {
    throttle(() => {
      if (this.shareUserInfo.uid) {
        if (object.scrollTop > 200) {
          this.hideShareInfo = true
        } else {
          this.hideShareInfo = false
        }
      }
      this.pageScrollTop = object.scrollTop

      if (this.scrollTime) {
        clearTimeout(this.scrollTime)
        this.scrollTime = null
      }
      this.scrollTime = setTimeout(() => {
        if (this.pageScrollTop < 60) {
          this.currentPos = 0
        } else if (this.showKoubei && !this.showComment && this.pageScrollTop > this.userKBPos - 71 && this.pageScrollTop < this.goodsDetailPos - 80) {
          this.currentPos = 1
        } else if (this.showKoubei && this.showComment && this.pageScrollTop > this.userKBPos - 71 && this.pageScrollTop < this.userCmPos - 80) {
          this.currentPos = 1
        } else if (this.showComment && this.pageScrollTop > this.userCmPos - 71 && this.pageScrollTop < this.goodsDetailPos - 80) {
          this.currentPos = 2
        } else if (this.pageScrollTop > this.goodsDetailPos - 80) {
          console.log(this.pageScrollTop, '距离', this.goodsDetailPos - 80, '详情')
          this.currentPos = 3
        }
      }, 500)
    }, 300)()
  },
  methods: {
    _reInit() {
      setTimeout(() => {
        this._initCommodity()
      }, 50)
    },
    async _initCommodity() {
      // if (Number(this.query.from_type) === 25) {
      //   // await this.initGroupList()
      // }
      uni.showLoading({
        title: '加载中'
      })
      let res = null
      const subForm = {
        goods_id: this.query.id,
        from_type: !this.query.from_type || this.query.from_type * 1 === 0 ? '1' : this.query.from_type,
        activity_id: this.query.activity_id || '',
        goods_type: !this.query.goods_type || this.query.goods_type * 1 === 0 ? '1' : this.query.goods_type,
        pack_type: !this.query.pack_type || this.query.pack_type * 1 === 0 ? '2' : this.query.pack_type
      }
      if (this.commodityType === 'boxGoods') {
        res = await this.$api.goodsApi.boxGoodsDetail({
          series_id: this.query.series_id,
          box_id: this.query.box_id
        })
      } else if (this.commodityType === 'bonusGift') {
        // 如果是3800 箱起礼包
        res = await this.$api.goodsApi.boxGoodsDetail({
          bonus_gift_id: this.query.bonus_gift_id
        })
      } else {
        res = await this.$api.goodsApi.goodsDetail(subForm)
      }
      this._formatData(res)
      this.getCartNums()
      uni.hideLoading()
      setTimeout(() => {
        uni.stopPullDownRefresh()
        this.refreshFlag = false
        this.getElScrollTop()
      }, 200)
    },
    _formatData(data) {
      const res = data.data
      if (!res || !res.goods) {
        uni.showToast({
          title: '该商品不存在',
          icon: 'none',
          duration: 2 * 1000
        })
        setTimeout(() => {
          uni.$off('login', this._reInit)
          uni.navigateBack()
        }, 2000)
        return
      }
      this.goodsOriginFromType = res.goods.from_type
      // 拼团处理
      if (res.group_buying_id !== null && res.group_buying_id) {
        this.isGroupGoods = true
        res.goods.from_type = 25
      } // 处理end
      const video = res.goods.banner_list.findIndex(item => item.media_type === 1)
      if (video > -1) {
        const tempVideo = res.goods.banner_list.splice(video, 1)
        res.goods.banner_list.unshift(tempVideo[0])
      }
      this.allData = res
      this.allData.starLength = Math.ceil(res.score || 5)
      // 组合套餐数据变更，取 rsp_data_list
      if (res.goods.type === 4) {
        // 主体下架的对应处理
        if (res.goods.status === 5) {
          res.rsp_data_list.map(item => {
            item.goods.status = 5
            return item
          })
        }
        // 会员层级价区间赋值
        let priceArea = [] // 价格区间
        const vipArr = [] // 会员价格
        const otherArr = [] // 会员价格
        const comboSkulist = []
        res.rsp_data_list.map(item => {
          // 价格区间 设置
          vipArr.push(item.goods.vip_price)
          otherArr.push(item.goods[getUserLevel()])
          // 判断是否可买
          let enableBuy = false
          if (item.goods.status === 3) {
            enableBuy = true
            // 只要套餐中有一个不可购买
            item.goods.goods_pack.pack.map(item => {
              if (item.status !== 3) {
                enableBuy = false
              }
            })
          }
          // 规格列表
          comboSkulist.push({
            // pic: item.goods.pic,
            // name: item.goods.title,
            ...item.goods,
            enable: enableBuy
          })
        })
        if (!this.token) {
          priceArea = [Math.min(...vipArr), Math.max(...vipArr)]
        }
        if (this.goods.from_type === 9) {
          priceArea = [Math.min(...otherArr), Math.max(...otherArr)]
        } else {
          priceArea = [Math.min(...vipArr), Math.max(...vipArr)]
        }
        res.goods.priceArea = priceArea
        res.goods.ComboPriceMin = priceArea[0]
        res.goods.ComboPriceMax = priceArea[1]
        res.goods.comboSkulist = comboSkulist;
        console.log(res.goods);
      }
      // 组合套餐 end
      this.goods = res.goods
      // 埋点
      this.sensor('commodityDetail')
      if (this.allData.share) {
        this.goods.shareUrl = this.allData.share.url
      }
      // #ifdef H5
      /* const param = {
        title: res.share.title, // 分享标题
        link: res.share.url, // 分享链接
        imgUrl: res.share.pic, // 分享图标
        desc: res.share.content // 分享描述
      }
      if (this.token) {
        AppUtils.ShareTimeline(param)
      } */
      // #endif
      if (res.gifts && this.commodityType === 'bonusGift') {
        this.allData.gifts = res.gifts
        this.allData.bonus_gift_id = this.query.bonus_gift_id
      }
      this.is_bookmark = !!res.is_bookmark
      this.initShare()
    },
    // 埋点
    sensor(event, data) {
      const from_type = this.query.from_type || this.goods.from_type
      let goodsArray = []
      let tempArray = []
      const commodity_id_list = []
      const commodity_name_list = []
      const first_commodity_list = []
      const second_commodity_list = []
      const price_of_commodity_list = []
      const real_price_list = []
      if (this.goods.goods_pack) {
        tempArray = this.goods.goods_pack.pack || []
        const present = (this.goods.goods_pack.present || []).map(i => {
          return {
            ...i,
            isPresent: true
          }
        })
        tempArray = tempArray.concat(present)
        for (let i = 0; i < tempArray.length; i++) {
          const iItem = tempArray[i]
          commodity_id_list.push(iItem.goods_id || this.goods.goods_id)
          commodity_name_list.push(iItem.title || this.goods.title)
          first_commodity_list.push(iItem.first_commodity)
          second_commodity_list.push(iItem.second_commodity)
          price_of_commodity_list.push(iItem.price ? iItem.price + '' : '')
          real_price_list.push(iItem.vip_price ? iItem.vip_price + '' : '')

          const gItem = {
            suit_id: this.goods.goods_id,
            suit_name: this.goods.title,
            commodity_id: iItem.goods_id || this.goods.goods_id,
            commodity_name: iItem.title || this.goods.title,
            first_commodity: iItem.first_commodity,
            second_commodity: iItem.second_commodity,
            from_type: this.query.from_type,
            activity_id: iItem.activity_id,
            price_of_commodity: iItem.price,
            real_price: iItem.vip_price,
            firstseat: this.firstseat,
            preseat: this.preseat
          }
          if (event === 'addToShoppingcart') {
            let selectedSkus = []
            let selectedSkusNumber = []
            if (iItem.isPresent) {
              selectedSkus = data.present_sku.split(',')
              selectedSkusNumber = data.present_sku_num.split(',')
            } else {
              selectedSkus = data.pack_sku.split(',')
              selectedSkusNumber = data.pack_sku_num.split(',')
            }
            let sku_code = ''
            let sku_name = ''
            let sku_num = 1
            for (let j = 0; j < selectedSkus.length; j++) {
              const jItem = selectedSkus[j]
              const index = iItem.sku_list.findIndex(sku_item => sku_item.sku_code === jItem)
              if (index > -1) {
                sku_code = jItem
                sku_num = selectedSkusNumber[j]
                sku_name = iItem.sku_list[index].properties_name
                break
              }
            }

            if (sku_code && sku_name) {
              gItem.sku_code = sku_code
              gItem.sku_name = sku_name
              gItem.commodity_number = sku_num * data.num
            } else {
              continue
            }
          }
          goodsArray.push(gItem)
        }

        const property = {
          suit_id: this.goods.goods_id,
          suit_name: this.goods.title,
          from_type,
          activity_id: this.goods.activity_id,
          price_of_commodity: this.goods.price,
          real_price: this.goods.vip_price,
          commodity_id_list: commodity_id_list,
          commodity_name_list: commodity_name_list,
          first_commodity_list: first_commodity_list,
          second_commodity_list: second_commodity_list,
          price_of_commodity_list: price_of_commodity_list,
          real_price_list: real_price_list,
          suit_commodity_number: tempArray.length,
          firstseat: this.firstseat,
          preseat: this.preseat
        }
        if (event === 'commodityDetail') {
          this.$sensorTrack('suitDetail', property)
        }
      } else {
        const item = {
          suit_id: '',
          suit_name: '',
          commodity_id: this.goods.goods_id,
          commodity_name: this.goods.title,
          first_commodity: this.goods.first_commodity,
          second_commodity: this.goods.second_commodity,
          from_type,
          activity_id: this.goods.activity_id,
          price_of_commodity: this.goods.price,
          real_price: this.goods.vip_price,
          firstseat: this.firstseat,
          preseat: this.preseat
        }
        if (event === 'addToShoppingcart') {
          const index = this.goods.sku_list.findIndex(i => i.sku_code === data.sku_code)
          if (index > -1) {
            item.sku_name = this.goods.sku_list[index].properties_name
          }
          item.commodity_number = data.num
        }
        goodsArray = [item]
      }

      goodsArray.map(i => {
        if (event !== 'commodityDetail') {
          delete i.firstseat
          delete i.preseat
        }
        if (event === 'colloctionCommodity') {
          i.is_collect = !data
        }
        this.$sensorTrack(event, i)
      })
    },
    collectCommodity(isCollect) {
      this.sensor('colloctionCommodity', isCollect)
    },
    async getCartNums() {
      if (!this.userInfo || !this.userInfo.uid || !this.showCartButton) {
        return false
      }
      const res = await this.$api.cartApi.getCartNums({})
      if (res.code) {
        return
      }
      this.cartNums = res.data
    },
    // 数据处理： 拼团
    handleActivityChange(val) {
      switch (val.module_name) {
        case 'groupBuy': // 拼团数据处理
          this.GroupBuyInfo = val.data
          this.$refs.nav.setGroup(val.data)
          this.goods.title = this.GroupBuyInfo.groupInfo.goodsName
          break
        default:
          ''
      }
    },
    // 拼团模块按钮点击处理
    groupHandle(param) {
      if (param.data.share) {
        this.takeInshareGroup = true
      } else {
        this.takeInshareGroup = false
      }
      this.takePartGroup(param, 'openGroup')
    },
    navButtonHandle(type) {
      if (!this.buyEnable && type !== 'shareDialog'&& type !== 'cartBtn') {
        if (!this.isSend) {
          uni.showToast({
            title: '您当前地址不在配送范围哦，修改后再购买吧~',
            icon: 'none',
            duration: 2 * 1000
          })
        }
        return
      }
      console.log(type);
      switch (type) {
        case 'buyBtn':
        case 'cartBtn':
        console.log(this.goods.type);
          if (this.goods.type === 2) {// 套餐
            this.$refs.option.showMask('package', type)
          } else if (this.goods.type === 4) {//组合套餐
            this.$refs.option.showMask('combo', type)
          } else {//单品
            this.$refs.option.showMask('singleGoods', type)
          }
          break
        case 'toPartnerAddress':
          this.$refs.option.showMask('partner', type)
          break
        case 'shareDialog':
          this.$refs.shareRef.show(this.allData)
          break
        case 'groupSingleBuy': // 团购单买
          this.takeInshareGroup = false
          if (this.goods.type === 2) {
            this.$refs.option.showMask('package', type)
            // 单独购买，最大值解禁
            this.$refs.option.$refs.package.resetMax()
          } else {
            this.$refs.option.showMask('singleGoods', type)
            // 单独购买，最大值解禁
            this.$refs.option.$refs.singleGoods.resetMax()
          }
          this.groupParam = {
            group_buying_id: '',
            group_id: '',
            from_type: this.goodsOriginFromType
          }
          break
        case 'openGroup': // 团购开团
          this.takeInshareGroup = false
          this.openGroup(type)
          break
        case 'boxApply': // 箱起云仓申购
          if (!this.userInfo.boxPermission || !this.userInfo.boxPermission.length) {
            return false
          }
          this.$refs.option.showMask('singleGoods', 'buyBtn')
          break
        case 'boxTake': // 箱起云仓提货
          if (this.goods.sku_list && this.goods.sku_list.length) {
            var sku_code = this.goods.sku_list[0].sku_code
          }
          this.$navigateTo(`/pagesBox/gift-bag/index?goods_id=${this.goods.box_id}&sku_code=${sku_code}&stock_id=${this.goods.stock_id}&series_id=${this.goods.series_id}`)
          break
        default:
          break
      }
    },
    // 参团
    takePartGroup(params, type) {
      switch (params.type) {
        case 'groupInPages': // 参与页面已经存在的团
          this.groupParam = {
            group_buying_id: this.GroupBuyInfo.idInfo.groupBuyingId,
            group_id: params.data.group_id,
            from_type: 25
          }
          break
        case 'shareGroup': // 参与链接分享出来的团
          this.groupParam = {
            group_buying_id: this.GroupBuyInfo.idInfo.groupBuyingId,
            group_id: params.data.group_id,
            from_type: 25,
            time_left: this.GroupBuyInfo.groupInfo.groupSecondLeft
          }
      }
      this.selfGroupResult = -2
      this.$sensorTrack('buttonClick', {
        button_name: '去拼单',
        button_key: 'group_join_in',
        page_name: '商品详情'
      })
      // 如果是套餐商品
      if (this.goods.type === 2) {
        this.$refs.option.showMask('package', type)
        // 单独购买，最大值解禁
        this.$refs.option.$refs.package.setMax()
      } else {
        this.$refs.option.showMask('singleGoods', type)
        // 限制拼团最大值
        this.$refs.option.$refs.singleGoods.setMax()
      }
    },
    // 发起拼团
    openGroup(type) {
      this.selfGroupResult = -2
      this.$sensorTrack('buttonClick', {
        button_name: '发起拼单',
        button_key: 'group_initiate',
        page_name: '商品详情'
      })
      this.groupParam = {
        group_buying_id: this.GroupBuyInfo.idInfo.groupBuyingId,
        from_type: 25
      }
      // 如果是套餐商品
      if (this.goods.type === 2) {
        this.$refs.option.showMask('package', type)
        // 单独购买，最大值解禁
        this.$refs.option.$refs.package.setMax()
      } else {
        this.$refs.option.showMask('singleGoods', type)
        // 限制拼团最大值
        this.$refs.option.$refs.singleGoods.setMax()
      }
    },
    dialogConfirm(buyObj) {
      console.log('dialogConfirm:',buyObj);
      if (!this.buyEnable && buyObj.buyType!=='cartBtn' && buyObj.buyType!=='skuCart') {
        if (!this.isSend) {
          uni.showToast({
            title: '您当前地址不在配送范围哦，修改后再购买吧~',
            icon: 'none',
            duration: 2 * 1000
          })
        }
        return
      }
      if (!this.isSend && buyObj.buyType!=='cartBtn' && buyObj.buyType!=='skuCart') {
        return
      }
      if (buyObj.buyType === 'buyBtn') {
        // this.toOrderSettle(buyObj)
        this.checkVIp(buyObj)
      }
      if (buyObj.buyType === 'groupSingleBuy' || buyObj.buyType === 'openGroup') {
        this.goods.from_type = buyObj.buyType === 'groupSingleBuy' ? this.goodsOriginFromType : 25
        this.toOrderSettle(buyObj)
      }
      if (buyObj.buyType === 'cartBtn') {
        this.handleAddToCart(buyObj)
      }
    },
    validProps(obj) {
      switch (obj.type) {
        case 'isSend':
          this.isSend = obj.isSend
          this.defaultAddress = obj.defaultAddress
          break
        case 'partner':
          this.partner = obj.partner
          this.partnerRole = obj.partnerRole
          break
        default:
          break
      }
    },
    async checkVIp(buyObj) {
      // 会员日校验： 1 可以购买， 2权限不够（该商品仅限vip会员购买） 3 不能购买，购买条件不符
      if (this.goods.from_type === 101) {
        const vipRes = await this.$api.goodsApi.getVipDayInfo({
          vipdayId: this.goods.activity_id,
          hideLoading: true
        })
        if (vipRes.success) {
          if (vipRes.data.code === 1) {
            this.toOrderSettle(buyObj)
          } else if (vipRes.data.code === 2) {
            this.$refs.confirmShow.show({
              title: '温馨提示',
              content: vipRes.data.msg || '该商品仅限VIP会员购买',
              cancleTxt: '直接购买',
              cancleTxtStyle: 'flex: 0 0 198rpx; border-radius:33rpx;height:66rpx;line-height:66rpx;border: 1rpx solid #ff759f;color: #ff759f;',
              yesTxt: '立即升级',
              yesTxtStyle: 'flex: 0 0 198rpx;border-radius:33rpx;height:66rpx;width:198rpx;line-height:66rpx;',
              containerStyle: 'padding: 0 60rpx 48rpx',
              yesCb: () => {
                getVipUrl().then(res => {
                  const info = res.data
                  if (info.vip_link) {
                    h5NavigateTo(info.vip_link)
                  }
                })
              },
              cancleCb: type => {
                if (type === 1) {
                  buyObj.isDefine = true
                  buyObj.from_type = 1
                  buyObj.activity_id = ''
                  this.toOrderSettle(buyObj)
                }
              }
            })
          } else if (vipRes.data.code === 3) {
            uni.showToast({
              title: vipRes.data && vipRes.data.msg ? vipRes.data.msg : '购买条件不符',
              icon: 'none'
            })
            return
          }
        }
      } else {
        this.toOrderSettle(buyObj)
      }
    },
    async toOrderSettle(buyObj) {
      if (this.query.from_type * 1 === 19) {
        const res = await this.$api.goodsApi.validataSignin({
          goods_id: this.goods.goods_id,
          goods_type: this.goods.type * 1 === 0 ? '1' : this.goods.type + '',
          activity_id: this.goods.activity_id,
          number: buyObj.count,
          from_type: this.goods.from_type * 1 === 0 ? '1' : this.allData.full_cut_id ? 24 : this.goods.from_type + ''
        })
        if (res.code || !res.data.result) {
          return
        }
      }
      // uni.showLoading({
      //   title: '加载中' 加了报错会出现很快过去的 真机
      // })
      let data = {
        goods_id: this.commodityType === 'boxGoods' ? this.goods.box_id : this.goods.goods_id,
        goods_type: this.goods.type * 1 === 0 ? '1' : this.goods.type + '',
        sku_code: '',
        activity_id: this.goods.activity_id,
        pack_list: [],
        pack_type: this.goods.pack_type * 1 === 0 ? 2 : this.goods.pack_type,
        present_list: [],
        num: buyObj.count,
        from_type: this.goods.from_type * 1 === 0 ? '1' : this.allData.full_cut_id ? 24 : this.goods.from_type + ''
      }
      // 如果是组合套餐则为 data 重新赋值
      if (this.goods.type === 4) {
        data = {
          goods_id: this.commodityType === 'boxGoods' ? buyObj.goods.box_id : buyObj.goods.goods_id,
          goods_type: buyObj.goods.type * 1 === 0 ? '1' : buyObj.goods.type + '',
          sku_code: '',
          activity_id: buyObj.goods.activity_id,
          pack_list: [],
          pack_type: buyObj.goods.pack_type * 1 === 0 ? 2 : buyObj.goods.pack_type,
          present_list: [],
          num: buyObj.count,
          from_type: buyObj.goods.from_type * 1 === 0 ? '1' : this.allData.full_cut_id ? 24 : buyObj.goods.from_type + ''
        }
      }
      if (buyObj.isDefine) {
        data.activity_id = buyObj.activity_id
        data.from_type = this.allData.full_cut_id ? 24 : buyObj.from_type
      }
      if (buyObj.maskType === 'package' || buyObj.maskType === 'combo') {
        buyObj.packageList.forEach(element => {
          data.pack_list.push({
            sku_code: element.selectedSkuItem.sku_code,
            num: element.selectedSkuItem.package_goods_number,
            activity_id: element.selectedSkuItem.activity_id,
            from_type: element.selectedSkuItem.from_type
          })
        })
      } else if (buyObj.maskType !== 'bonusGift') {
        data.sku_code = buyObj.selectedSkuItem.sku_code
      }
      if (buyObj.presentList && buyObj.presentList.length) {
        const presentSku = []
        buyObj.presentList.forEach(element => {
          presentSku.push({
            sku_code: element.selectedSkuItem.sku_code,
            num: element.selectedSkuItem.package_goods_number,
            activity_id: element.selectedSkuItem.activity_id,
            from_type: element.selectedSkuItem.from_type
          })
        })
        data.present_list = presentSku
      }
      // 如果是正常的拼团参数，并且进行拼团购买，则根据拼团改变个别传参
      if (this.goods.from_type === 25) {
        if (buyObj.count > this.GroupBuyInfo.groupInfo.groupLimit) {
          uni.showToast({
            title: '超过限购数额，最多购买' + this.GroupBuyInfo.groupInfo.groupLimit + '件',
            icon: 'none',
            duration: 2 * 1000
          })
          // uni.hideLoading()
          return
        }
        data.from_type = 25
        // 如果是新开团
        if (this.groupParam.group_buying_id && this.groupParam.group_id === undefined) {
          // groupBuyingId 为活动id
          data.group_buying_id = this.groupParam.group_buying_id
        }
        //  如果是参团
        if (this.groupParam.group_buying_id && this.groupParam.group_id >= 0) {
          // groupBuyingSponsorId 为团id
          data.group_buying_id = this.groupParam.group_buying_id
          if (typeof this.groupParam.group_id === 'number') {
            data.group_id = JSON.stringify(this.groupParam.group_id)
          } else {
            data.group_id = this.groupParam.group_id
          }
        }
      }
      // return

      // 校验购买数量防止传参无意义报错
      const numCheckResult = inputCheckNumber(buyObj.count)
      if (!numCheckResult) {
        // uni.hideLoading()
        // buyObj.count = 1
        return
      }
      data.buyData = JSON.stringify([data])
      if (this.commodityType === 'bonusGift') {
        // 如果是3800箱起礼包
        data.buyData = buyObj.buyData
      }
      if (this.goods.from_type === 13) {
        const goodsCanBuy = await this.$api.orderApi.goodsValidate({
          num: data.num,
          pack_type: data.pack_type,
          activity_id: data.activity_id,
          goods_type: data.goods_type,
          goods_id: data.goods_id,
          from_type: data.from_type
        })
        if (goodsCanBuy.code) {
          // uni.hideLoading()
          return
        }
      }
      // 判断是否使用优惠券
      let userCoupon = 0
      if (this.showCoupon) {
        userCoupon = 1
      } else {
        userCoupon = this.GroupBuyInfo.groupInfo ? 1 : 0
        if (this.goods.type === 4) {
          userCoupon = 1
        }
      }
      const settleData = {
        is_used_coupon: userCoupon,
        shopping_list: data.buyData,
        shipping_address_id: this.defaultAddress.address_id
      }
      // 如果是云仓申购 增加入参
      if (this.allData.series_type === 3) {
        // 2为下单权限
        settleData.stock_goods_id = this.goods.box_id
        if (this.goods.sku_list && this.goods.sku_list.length) {
          settleData.stock_sku_code = this.goods.sku_list[0].sku_code
        }
        if (this.userInfo.boxPermission && this.userInfo.boxPermission.includes(2)) {
          settleData.new_box_order_type = 1
        } else {
          settleData.new_box_order_type = 2
          this.$store.dispatch('setGoodsTemp', {
            shopping_list: data.buyData,
            data: {
              coupon_list: [],
              hongbao_list: [],
              unusable_coupon_list: [],
              shopping_items: {
                activity_item_list: [],
                item_list: [
                  {
                    goods_id: this.goods.box_id,
                    title: this.goods.title,
                    num: buyObj.count,
                    vip_price: this.goods.director_price,
                    sku_code: this.goods.sku_list && this.goods.sku_list.length ? this.goods.sku_list[0].sku_code : '',
                    pic: this.goods.pic,
                    stock_number: this.goods.stock_number,
                    need_change_num: true
                  }
                ]
              }
            },
            settleData
          })
          this.$navigateTo(
            formatUrlParam('/pagesBox/pick-up/index', {
              boxType: 'apply'
            })
          )
          return
        }
      }
      const res = await this.$api.orderApi.orderSettle(settleData)
      // uni.hideLoading()
      this.$store.dispatch('setGoodsTemp', {
        shopping_list: data.buyData,
        data: res.data,
        settleData
      })
      if (res.code || !res || !res.data) {
        return
      }

      // 如果有设置剩余时间字段
      if (this.GroupBuyInfo.groupInfo) {
        if (this.GroupBuyInfo.groupInfo.groupSecondLeft === 0 && this.takeInshareGroup) {
          if (this.selfGroupResult === 1) {
            uni.showToast({
              title: '您已经参加过该团,不可重复参加',
              icon: 'none',
              duration: 2 * 1000
            })
            return
          }
          // 先缓存购买信息再做转跳操作
          const itemInfo = JSON.stringify({
            shopping_list: data.buyData,
            data: res.data
          })
          uni.setStorageSync('_group_item_info_', itemInfo)
          const groupResultQuery = {
            group_id: this.GroupBuyInfo.idInfo.groupBuyingSponsorId,
            group_full: true
          }
          const url = formatUrlParam('/pagesActivity/group-buy/result', groupResultQuery)
          this.$navigateTo(url)
          return
        }
      }
      if (this.selfGroupResult === 1) {
        uni.showToast({
          title: '您已经参加过该团,不可重复参加',
          icon: 'none',
          duration: 2 * 1000
        })
        return
      }
      const params = {}
      if (this.query.bonus_gift_id) {
        params.bonus_gift_id = this.query.bonus_gift_id
      }
      if (this.query.invite_code) {
        let code = ''
        if (typeof this.query.invite_code === 'object') {
          code = this.query.invite_code[0]
        } else {
          code = this.query.invite_code
        }
        params['invite_code'] = code
      }
      uni.setStorageSync('preseat', '商品详情')
      uni.setStorageSync('firstseat', this.firstseat)
      // 箱起云仓跳转逻辑
      if (this.allData.series_type === 3) {
        // 2为下单权限
        this.$navigateTo(
          formatUrlParam('/pagesBox/pick-up/index', {
            boxType: 'buy'
          })
        )
        return
      }
      this.$navigateTo(formatUrlParam('/pagesOrder/orderCheck/index', params))
    },
    async handleAddToCart(buyObj) {
      const data = {
        goods_id: this.goods.goods_id,
        goods_type: this.goods.type * 1 === 0 ? '1' : this.goods.type,
        sku_code: '',
        activity_id: this.goods.activity_id,
        pack_sku: [],
        pack_type: this.goods.pack_type * 1 === 0 ? '2' : this.goods.pack_type,
        present_sku: '',
        num: buyObj.count,
        from_type: this.goods.from_type * 1 === 0 ? '1' : this.goods.from_type
      }
      if (buyObj.maskType === 'packageCart') {
        let enableNext = true
        const pack_sku_num = []
        buyObj.packageList.forEach(element => {
          if (!element.selectedSkuItem) {
            enableNext = false
          }
          data.pack_sku.push(element.selectedSkuItem.sku_code)
          pack_sku_num.push(element.selectedSkuItem.package_goods_number)
        })
        if (!enableNext) {
          uni.showToast({
            title: '请完整选择套餐',
            icon: 'none',
            duration: 2 * 1000
          })
          return
        }
        data.pack_sku = data.pack_sku.join(',')
        data.pack_sku_num = pack_sku_num.join(',')
        // this.collectSuitSensor('addSuitToShoppingcart', { suit_number: data.num })
      } else {
        // this.collectGoodsSensor('addToShoppingcart', { commodity_number: data.num, sku_name: this.singleGoods.selectedSkuItem.properties_name })
        if (!buyObj.selectedSkuItem) {
          uni.showToast({
            title: '请选择商品规格',
            icon: 'none',
            duration: 2 * 1000
          })
          return
        }
        data.sku_code = buyObj.selectedSkuItem.sku_code
      }
      if (buyObj.presentList && buyObj.presentList.length) {
        const presentSku = []
        const present_sku_num = []
        buyObj.presentList.forEach(element => {
          presentSku.push(element.selectedSkuItem.sku_code)
          present_sku_num.push(element.selectedSkuItem.package_goods_number)
        })
        data.present_sku_num = present_sku_num.join(',')
        data.present_sku = presentSku.join(',')
      }
      this.sensor('addToShoppingcart', data)
      const res = await this.$api.cartApi.addShoppingCart(data)
      if (res.code) {
        return
      }
      this.getCartNums()
      uni.showToast({
        title: '添加成功',
        icon: 'none',
        duration: 2 * 1000
      })
      // this.cartNums += buyObj.count
    },
    toHome() {
      this.$navigateTo('/pages/home/index', {}, 'switchTab')
      this.headerMenu = false
    },
    linktoCart() {
      this.$navigateTo('/pages/cart/index')
      this.headerMenu = false
      // window.__sensors__.track('receiveDiscount', {
      //   button_name: '商品详情-前往购物车',
      //   button_key: 'goods_detail_shopping_cart'
      // })
    },
    goHome() {
      uni.reLaunch({ url: '/pages/home/index' })
    },
    _pageBack() {
      uni.$off('login', this._reInit)
      uni.navigateBack()
    },
    checkSkuNum(item) {
      if (!item.sku_list || !item.sku_list.length) {
        return false
      }
      let num = 0
      item.sku_list.forEach(element => {
        num += element.num
      })
      return num > 0
    },
    // 有invitedCode 获取分享者信息
    async getShareUser(option) {
      // const urlCode = option.invite_code || ''
      // let invite_code = uni.getStorageSync('share_code')
      // let invite_code = this.inviteCode
      // if (urlCode) {
      //   const codeArr = urlCode.split(',')
      //   invite_code = codeArr.length > 0 ? codeArr[0] : invite_code
      //   uni.setStorageSync('share_code', invite_code)
      // }
      const invite_code = option.invite_code || option.inviteCode
      console.log('invite_code', invite_code)
      if (!invite_code) return
      let showShareInfo = true
      if (!this.token) {
        // 未登录 ---》一律展示
        showShareInfo = true
      } else if (this.token && this.userInfo.referral_code) {
        // 登录了 ---> 并且绑定的关系
        showShareInfo = false
      } else if (this.token && this.userInfo.current_member_card_type === 3) {
        // 登陆且级别是董事---》不展示
        showShareInfo = false
      } else if (this.token && !this.userInfo.referral_code) {
        // 登陆且没上级，再请求一次判断是否绑定
        const res = await this.$api.mineApi.getMy()
        if (!res.code && res.data && res.data.user) {
          if (res.data.user.referral_code) {
            showShareInfo = false
          }
        }
      }
      console.log(showShareInfo)
      if (showShareInfo) {
        const res = await this.$api.mineApi.getInfoByInviteCode(invite_code)
        console.log('getInfoByInviteCode', res)
        if (res.success) {
          this.shareUserInfo = res.data || {}
          if (!this.shareUserInfo.head_img) {
            this.shareUserInfo.head_img = '/static/images/mine/touxiang.png'
          }
        }
      }
    },
    // 点击tab 滑动到指定位置
    scrollToTab(type) {
      if (type === 0) {
        uni.pageScrollTo({
          scrollTop: 51,
          duration: 300
        })
        this.currentPos = 0
      } else if (type === 1) {
        uni.pageScrollTo({
          scrollTop: this.userKBPos - 70,
          duration: 300
        })
        this.currentPos = 1
      } else if (type === 2) {
        uni.pageScrollTo({
          scrollTop: this.userCmPos - 100,
          duration: 300
        })
        this.currentPos = 2
      } else if (type === 3) {
        uni.pageScrollTo({
          scrollTop: this.goodsDetailPos - 70,
          duration: 300
        })
        this.currentPos = 3
      }
    },
    // 获取各个描点距离顶部距离
    getElScrollTop() {
      const query = uni.createSelectorQuery().in(this)
      if (this.showKoubei) {
        query
          .select('#userKB')
          .boundingClientRect(data => {
            this.userKBPos = data.top
          })
          .exec()
      }
      if (this.showComment) {
        query
          .select('#userCm')
          .boundingClientRect(data => {
            this.userCmPos = data.top
          })
          .exec()
      }
      query
        .select('#goodsDetail')
        .boundingClientRect(data => {
          this.goodsDetailPos = data.top
        })
        .exec()
    },
    handleToggle() {
      this.hideShareInfo = !this.hideShareInfo
    },

    // 分享初始化
    initShare(groupFlag) {
      if (this.token) {
        if (this.GroupBuyInfo.groupInfo && groupFlag) {
          let info
          if (this.GroupBuyInfo.groupInfo.inviteBtn) {
            info = this.GroupBuyInfo.groupInfo.inviteBtn
          } else {
            info = this.GroupBuyInfo.groupInfo.shareBtn
          }
          // 替换url
          console.log(info.url, '666------')
          const url = getQueryString('path', info.url)
          this.shareOption = {
            share_title: info.title,
            share_url: decodeURIComponent(url),
            share_icon: info.pic,
            share_content: info.content
          }
        } else if (this.allData && (this.allData.share || this.allData.goods) && (this.showShareButton || this.GroupBuyInfo.groupInfo)) {
          this.shareOption.share_url = ''
          this.shareOption.share_title = this.allData.share ? this.allData.share.title : this.allData.goods.title
          this.shareOption.share_content = this.allData.share ? this.allData.share.content : this.allData.goods.subtitle
          this.shareOption.share_icon = this.allData.share ? this.allData.share.pic : this.allData.goods.pic
          this.shareOption.share_image = this.allData.share ? this.allData.share.pic : this.allData.goods.pic
        }
        this.showShare()
      } else {
        console.log('2------------')
        this.hideShare()
      }
    }
  }
}
</script>
